;; Set current window to named Window e.g.
;; (with-window "Logon - Microsoft Internet Explorer"  
;;    (click-button "Logon") ) 
;; 
(define-syntax with-window 
  (syntax-rules () 
    ((_ name expression ...) 
     (let ((old-window (current-window))) 
       (dynamic-wind 
         (lambda () (current-window (find-window name))) 
         (lambda () expression ...) 
         (lambda () (current-window old-window)
                    )))))) 

;; Set current window to a new Window e.g.
;; (with-new-window "calc.exe"  
;;    (click-button "=") ) 
;; 
(define-syntax with-new-window 
  (syntax-rules () 
    ((_ name expression ...) 
     (let ((old-window (current-window))) 
       (dynamic-wind 
         (lambda () (current-window (_new-window name))) 
         (lambda () expression ...) 
         (lambda () (current-window old-window)
                    )))))) 


;; Set current window to a new Internet Explorer window with URL e.g.
;; (with-new-browser "http://www.google.co.uk"  
;;    (click-button "Search") ) 
;; 
(define-syntax with-new-browser 
  (syntax-rules () 
    ((_ url expression ...) 
     (let ((old-window (current-window))) 
       (dynamic-wind 
         (lambda () (current-window (create-browser url))) 
         (lambda () expression ...) 
         (lambda () (current-window old-window)
                    )))))) 

